import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    count: 1,
    baseInfo: {
      userInfo: {}, // 用户基本信息
    },
  },
  mutations: {
    increaseCount(state) {
      state.count += 1
    },
    setBaseInfo(state, data) {
      state.baseInfo = { ...state.baseInfo, ...data }
    },
  },
  actions: {
    // 获取用户信息
    getBaseInfo({ commit }) {
      axios.get('/api/user/baseInfo').then(res => {
        res = res.data
        if (res && res.success) {
          commit('setBaseInfo', res.data)
        }
      })
    },
  },
})

export default store
